/**
 * @brief fork和execve实验
 */

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static void child() {
    char* argv[] = {"hello", "linux", NULL};
    printf("child: pid = %d\n", getpid());
    fflush(stdout);
    execve("bin_echo", argv, NULL);
}

static void parent() {
    printf("parent: pid = %d\n", getpid());
    fflush(stdout);
    exit(EXIT_SUCCESS);
}

int main(void) {
    int ret;
    ret = fork();
    if (ret == -1) {
        err(EXIT_FAILURE, "fork");
    }

    if (ret == 0) {
        child();
    } else {
        parent();
    }

    err(EXIT_FAILURE, "shudn't reach here");
}